package com.ccsoft.zknote.exception;

import com.ccsoft.zknote.enums.EventCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author chanchaw
 * @create 2023-07-08 22:44
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ServiceException extends Exception {
    private Integer code;
    private Boolean success;
    private String msg;
    private Object data;

    public ServiceException(EventCode eventCode) {
        this.code = eventCode.getCode();
        this.success = false;
        this.msg = eventCode.getDesc();
    }

    // 使用状态码，但是自定义提示文案
    public ServiceException(EventCode eventCode, String msg) {
        this.code = eventCode.getCode();
        this.success = false;
        this.msg = msg;
    }

    public ServiceException(Integer code, String msg) {
        this.code = code;
        this.success = false;
        this.msg = msg;
    }
}
